﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using WTM.Model;


namespace WTM.ViewModel.BaseData.WorksVMs
{
    public partial class WorksListVM : BasePagedListVM<Works_View, WorksSearcher>
    {

        protected override IEnumerable<IGridColumn<Works_View>> InitGridHeader()
        {
            return new List<GridColumn<Works_View>>{
                this.MakeGridHeader(x => x.work),
                this.MakeGridHeader(x => x.Dwqy),
                this.MakeGridHeader(x => x.Dwmc),
                this.MakeGridHeader(x => x.Dwbm),
                this.MakeGridHeader(x => x.Dwlx),
                this.MakeGridHeader(x => x.Dwdz),
                this.MakeGridHeader(x => x.Lxdh),
                this.MakeGridHeader(x => x.Lxr),
                this.MakeGridHeader(x => x.PhotoId).SetFormat(PhotoIdFormat),
                this.MakeGridHeader(x => x.WorkNr),
                this.MakeGridHeader(x => x.NlYq_1),
                this.MakeGridHeader(x => x.NlYq_2),
                this.MakeGridHeader(x => x.XbYq),
                this.MakeGridHeader(x => x.WorkYq_1),
                this.MakeGridHeader(x => x.WorkYq_2),
                this.MakeGridHeader(x => x.Xzdy),
                this.MakeGridHeader(x => x.Remark),
                this.MakeGridHeaderAction(width: 200)
            };
        }
        private List<ColumnFormatInfo> PhotoIdFormat(Works_View entity, object val)
        {
            return new List<ColumnFormatInfo>
            {
                ColumnFormatInfo.MakeDownloadButton(ButtonTypesEnum.Button,entity.PhotoId),
                ColumnFormatInfo.MakeViewButton(ButtonTypesEnum.Button,entity.PhotoId,640,480),
            };
        }


        public override IOrderedQueryable<Works_View> GetSearchQuery()
        {
            var query = DC.Set<Works>()
                .CheckContain(Searcher.work, x=>x.work)
                .CheckEqual(Searcher.Dwqy, x=>x.Dwqy)
                .CheckContain(Searcher.Dwmc, x=>x.Dwmc)
                .CheckContain(Searcher.Dwbm, x=>x.Dwbm)
                .CheckEqual(Searcher.Dwlx, x=>x.Dwlx)
                .CheckContain(Searcher.Dwdz, x=>x.Dwdz)
                .CheckContain(Searcher.Lxdh, x=>x.Lxdh)
                .CheckContain(Searcher.Lxr, x=>x.Lxr)
                .CheckContain(Searcher.WorkNr, x=>x.WorkNr)
                .CheckEqual(Searcher.NlYq_1, x=>x.NlYq_1)
                .CheckEqual(Searcher.NlYq_2, x=>x.NlYq_2)
                .CheckEqual(Searcher.XbYq, x=>x.XbYq)
                .CheckContain(Searcher.WorkYq_1, x=>x.WorkYq_1)
                .CheckContain(Searcher.WorkYq_2, x=>x.WorkYq_2)
                .CheckContain(Searcher.Xzdy, x=>x.Xzdy)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .Select(x => new Works_View
                {
				    ID = x.ID,
                    work = x.work,
                    Dwqy = x.Dwqy,
                    Dwmc = x.Dwmc,
                    Dwbm = x.Dwbm,
                    Dwlx = x.Dwlx,
                    Dwdz = x.Dwdz,
                    Lxdh = x.Lxdh,
                    Lxr = x.Lxr,
                    PhotoId = x.PhotoId,
                    WorkNr = x.WorkNr,
                    NlYq_1 = x.NlYq_1,
                    NlYq_2 = x.NlYq_2,
                    XbYq = x.XbYq,
                    WorkYq_1 = x.WorkYq_1,
                    WorkYq_2 = x.WorkYq_2,
                    Xzdy = x.Xzdy,
                    Remark = x.Remark,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class Works_View : Works{

    }
}
